package com.example.bbfindhouse.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.bbfindhouse.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class zufangActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zufang);
        List<Map<String, Object>> dataList = new ArrayList<>();
        Map<String, Object> house1 = new HashMap<>();
        house1.put("image", R.drawable.ic_house1);
        house1.put("name", "中海河山郡");
        house1.put("price", "5000元/平");
        house1.put("area", "丰满区 四合");
        house1.put("buildArea", "建面87 - 125㎡");
        house1.put("roomType", "2/3居");
        dataList.add(house1);

        Map<String, Object> house2 = new HashMap<>();
        house2.put("image", R.drawable.ic_house2);
        house2.put("name", "路弘·阳光华府");
        house2.put("price", "7300元/平");
        house2.put("area", "昌邑区 万达广场");
        house2.put("buildArea", "建面87 - 126㎡");
        house2.put("roomType", "2/3居");
        dataList.add(house2);

        SimpleAdapter adapter = new SimpleAdapter(this, dataList, R.layout.house_item,
                new String[]{"image", "name", "price", "area", "buildArea", "roomType"},
                new int[]{R.id.house_image, R.id.house_name, R.id.house_price, R.id.house_area, R.id.house_build_area, R.id.house_room_type});

        ListView listView = findViewById(R.id.house_list);
        listView.setAdapter(adapter);

        // 处理热门楼盘图片按钮点击事件
        findViewById(R.id.house_image1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(zufangActivity.this, "点击了中海河山郡图片", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.house_image2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(zufangActivity.this, "点击了路弘·阳光华府图片", Toast.LENGTH_SHORT).show();
            }
        });

        // 处理分类按钮点击事件
        findViewById(R.id.all_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(zufangActivity.this, "点击了全部按钮", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.building_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(zufangActivity.this, "点击了只看楼盘按钮", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.residential_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(zufangActivity.this, "点击了住宅按钮", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.for_sale_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(zufangActivity.this, "点击了在售按钮", Toast.LENGTH_SHORT).show();
            }
        });

        // 处理列表项点击事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Map<String, Object> item = (Map<String, Object>) parent.getItemAtPosition(position);
                Toast.makeText(zufangActivity.this, "点击了 " + item.get("name") + " 列表项", Toast.LENGTH_SHORT).show();
            }
        });
    }
}